using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace vnMcdonald.Models.Mapping
{
    public class OrderMap : EntityTypeConfiguration<Order>
    {
        public OrderMap()
        {
            // Primary Key
            this.HasKey(t => t.OrderId);

            // Properties
            this.Property(t => t.Codes)
                .HasMaxLength(20);

            this.Property(t => t.Recipient)
                .HasMaxLength(50);

            this.Property(t => t.Phone)
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("Orders");
            this.Property(t => t.OrderId).HasColumnName("OrderId");
            this.Property(t => t.Codes).HasColumnName("Codes");
            this.Property(t => t.TotalPrice).HasColumnName("TotalPrice");
            this.Property(t => t.CreateDate).HasColumnName("CreateDate");
            this.Property(t => t.Recipient).HasColumnName("Recipient");
            this.Property(t => t.Address).HasColumnName("Address");
            this.Property(t => t.Phone).HasColumnName("Phone");
            this.Property(t => t.UserId).HasColumnName("UserId");
            this.Property(t => t.Note).HasColumnName("Note");
            this.Property(t => t.Status).HasColumnName("Status");

            // Relationships
            this.HasOptional(t => t.User)
                .WithMany(t => t.Orders)
                .HasForeignKey(d => d.UserId);

        }
    }
}
